package com.obas.common.command {
    import com.ease.util.events.MethodReturnEvent;
    import com.ease.framework.ViewRegistry;
    import com.ease.flex.remoting.ServiceManagerComObasNetworkFlexRemoting;
	import com.obas.common.event.DimensionOperationEvent;
	import com.obas.business.device.event.DeviceManagementEvent;
	import com.obas.business.customer.event.CustomerManagementEvent;
	import com.obas.business.topo.event.TopoVisualizationEvent;
    import flash.events.EventDispatcher;
	import com.ease.common.vo.Pagination;
	import com.ease.common.vo.Ordering;
  
   [Event(name="{com.obas.business.device.event.DeviceManagementEvent.RETURN_ID}", type="com.obas.business.device.event.DeviceManagementEvent")]
   [Event(name="{com.obas.business.customer.event.CustomerManagementEvent.RETURN_ID}", type="com.obas.business.customer.event.CustomerManagementEvent")]   
   [Event(name="{com.obas.business.topo.event.TopoVisualizationEvent.RETURN_ID}", type="com.obas.business.topo.event.TopoVisualizationEvent")]   
   [Event(name="{com.obas.common.event.DimensionOperationEvent.RETURN_ID}", type="com.obas.common.event.DimensionOperationEvent")]   
   public class NetworkLibCommand extends EventDispatcher {	   
	   
	   [RequestHandler("{com.obas.common.event.DimensionOperationEvent.REQUEST_ID}")]
	   public static function onDimensionOperationEvent(request:DimensionOperationEvent):void {
		   
		   switch(request.actionType) {
//			   case DimensionOperationEvent.OPERATION_getUserAppScore:
//				   ServiceManagerComObasNetworkFlexRemoting.getAnalogyManagementService().findUserAppGrid(request.analogyParam , onOperationReturn, request);
//				   break; 
			   case DimensionOperationEvent.OPERATION_findUserBusinessExperienceIndicatorGrid:
				   ServiceManagerComObasNetworkFlexRemoting.getAnalogyManagementService().findUserBusinessExperienceIndicatorGrid(request.analogyParam , onOperationReturn, request);
				   break; 
			   case DimensionOperationEvent.OPERATION_findUserBusinessExperienceUserGrid:
				   ServiceManagerComObasNetworkFlexRemoting.getAnalogyManagementService().findUserBusinessExperienceUserGrid(request.analogyParam , onOperationReturn, request);
				   break;
			   case DimensionOperationEvent.OPERATION_findUserNetworkExperienceIndicatorGrid:
				   ServiceManagerComObasNetworkFlexRemoting.getAnalogyManagementService().findUserNetworkExperienceIndicatorGrid(request.analogyParam , onOperationReturn, request);
				   break; 
			   case DimensionOperationEvent.OPERATION_findUserNetworkExperienceUserGrid:
				   ServiceManagerComObasNetworkFlexRemoting.getAnalogyManagementService().findUserNetworkExperienceUserGrid(request.analogyParam , onOperationReturn, request);
				   break;
			   case DimensionOperationEvent.OPERATION_GET_USERAPP_HISTORY_RANK:
				   ServiceManagerComObasNetworkFlexRemoting.getAnalogyManagementService().findUserAppHistroyRank(request.analogyParam , onOperationReturn, request);
				   break; 
			   default:
				   break;
		   }
		   
	   }
	   
	   [RequestHandler("{com.obas.business.topo.event.TopoVisualizationEvent.REQUEST_ID}")]
	   public static function onTopoVisualizationEvent(request:TopoVisualizationEvent):void {
		   switch(request.actionType) {
			   case TopoVisualizationEvent.OPERATION_VIEW_USER_ROUTE:
				   ServiceManagerComObasNetworkFlexRemoting.getNetworkTopologyManagementService().viewRoute(request.accountId, onOperationReturn, request);
				   break; 
			   case TopoVisualizationEvent.OPERATION_VIEW_NETWORK_TOPOLOGY:
				   ServiceManagerComObasNetworkFlexRemoting.getNetworkTopologyManagementService().viewTopology(request.deviceId, onOperationReturn, request);
				   break;
			   default:
				   break;
		   }
	   }
	   
	   [RequestHandler("{com.obas.business.device.event.DeviceManagementEvent.REQUEST_ID}")]
	   public static function onDeviceManagementEvent(request:DeviceManagementEvent):void {
		   switch(request.actionType) {
			   case DeviceManagementEvent.OPERATION_QUERY:
				   ServiceManagerComObasNetworkFlexRemoting.getDeviceAccessService().findPagination("find",null,request.ordering,request.pagination, onOperationReturn, request);
				   break; 
			   case DeviceManagementEvent.OPERATION_CREATE:
				   ServiceManagerComObasNetworkFlexRemoting.getDeviceAccessService().save(request.device, onOperationReturn, request);
				   break; 
			   case DeviceManagementEvent.OPERATION_REMOVE:
				   ServiceManagerComObasNetworkFlexRemoting.getDeviceAccessService().removeList(request.devices, onOperationReturn, request);
				   break; 
//			   case DeviceManagementEvent.OPERATION_RETRIEVE_USERMACADDRESS:
//				   ServiceManagerComObasNetworkFlexRemoting.getElementLoaderManagementService().loadDeviceMacAddress(request.devices, onOperationReturn, request);
//				   break;	
			   default:
				  break;
		   }
	   }
	   	   
	   [RequestHandler("{com.obas.business.customer.event.CustomerManagementEvent.REQUEST_ID}")]
	   public static function onCustomerManagementEvent(request:CustomerManagementEvent):void {
		   switch(request.actionType) {
			   case CustomerManagementEvent.OPERATION_QUERY:
				   ServiceManagerComObasNetworkFlexRemoting.getCustomerAccessService().findPagination("find",null,request.ordering,request.pagination, onOperationReturn, request);
				   break; 
			   case CustomerManagementEvent.OPERATION_CREATE:
				   ServiceManagerComObasNetworkFlexRemoting.getCustomerAccessService().save(request.account, onOperationReturn, request);
				   break; 			   
			   case CustomerManagementEvent.OPERATION_REMOVE:
				   ServiceManagerComObasNetworkFlexRemoting.getCustomerAccessService().removeList(request.accounts, onOperationReturn, request);
				   break; 
			   default:
				   break;
		   }
	   }
	   

      private static function onOperationReturn(event:MethodReturnEvent):void {
         ServiceManagerComObasNetworkFlexRemoting.onOperationReturn(getInstance(), event);
      }

      private static var _instance:NetworkLibCommand = null;

      private static function getInstance():NetworkLibCommand {
         if (_instance == null) {
            _instance = new NetworkLibCommand();
            ViewRegistry.instance.eventBus.addParticipant(_instance, true);
         }

         return _instance;
      }
   }
}